package com.financing.platform.common;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import com.financing.platform.util.Constants;
import org.apache.commons.lang.StringUtils;

public class CommonConstantUtil {
	/**返利为百分比 */
	public static final String REBATE_RATIO = "01";
	/** 返利为金额 */
	public static final String REBATE_AMOUNT = "02";
	
	public static Map<String, String> tradeMap = null;
	public static Map<String, String> certTypeMap = null;
	public static Map<String, String> productCityMap = null;
	public static Map<String, String> customerFocusBehaviorMap = null;
	public static Map<String, String> productTypeMap = null;
	static{
		tradeMap = new HashMap<String, String>();
		tradeMap.put("01", "基金");
		tradeMap.put("02", "证劵");
		tradeMap.put("03", "期货");
		tradeMap.put("04", "投资");
		tradeMap.put("05", "银行");
		tradeMap.put("06", "保险");
		tradeMap.put("07", "信托");
		tradeMap.put("08", "担保");
		tradeMap.put("09", "拍卖");
		tradeMap.put("10", "典当");
		tradeMap.put("11", "其他");

		certTypeMap = new HashMap<String, String>();
		certTypeMap.put("01", "证劵执业资格");
		certTypeMap.put("02", "基金执业资格");
		certTypeMap.put("03", "期货执业资格");
		certTypeMap.put("04", "黄金投资分析师职业资格");
		certTypeMap.put("05", "上海金交所交易员资格");
		certTypeMap.put("06", "理财规划师职业资格");
		certTypeMap.put("07", "保险咨询");
		certTypeMap.put("08", "港股投资咨询");
		certTypeMap.put("09", "美国证券期货执业资格");
		certTypeMap.put("10", "金融理财师职业资格");
		certTypeMap.put("11", "特许金融分析师资格");
		certTypeMap.put("12", "注册国际投资分析师资格");



		productCityMap = new TreeMap<String, String>();
		productCityMap.put("01","北京");
		productCityMap.put("02","天津");
		productCityMap.put("03","上海");
		productCityMap.put("04","河北");
		productCityMap.put("05","广东");
		productCityMap.put("06","浙江");
		productCityMap.put("07","江苏");
		productCityMap.put("08","重庆");
		productCityMap.put("09","山东");
		productCityMap.put("10","福建");
		productCityMap.put("11","江西");
		productCityMap.put("12","内蒙古");
		productCityMap.put("13","辽宁");
		productCityMap.put("14","吉林");
		productCityMap.put("15","黑龙江");
		productCityMap.put("16","安徽");
		productCityMap.put("17","山西");
		productCityMap.put("18","河南");
		productCityMap.put("19","湖北");
		productCityMap.put("20","湖南");
		productCityMap.put("21","广西");
		productCityMap.put("22","海南");
		productCityMap.put("23","四川");
		productCityMap.put("24","贵州");
		productCityMap.put("25","云南");
		productCityMap.put("26","西藏");
		productCityMap.put("27","陕西");
		productCityMap.put("28","甘肃");
		productCityMap.put("29","青海");
		productCityMap.put("30","宁夏");
		productCityMap.put("31","新疆");


		customerFocusBehaviorMap = new TreeMap<String, String>();
		customerFocusBehaviorMap.put("110507","金策师私募产品详情页");
		customerFocusBehaviorMap.put("110508","金策师{0}产品详情页");
		customerFocusBehaviorMap.put("110509","金策师私募产品详情页附件查看");
		customerFocusBehaviorMap.put("110510","金策师{0}产品详情页附件查看");
		customerFocusBehaviorMap.put("120201","SFA网页私募产品详情页");
		customerFocusBehaviorMap.put("120202","SFA网页{0}产品详情页");
		customerFocusBehaviorMap.put("120203","SFA网页私募产品详情页附件查看");
		customerFocusBehaviorMap.put("120204","SFA网页{0}产品详情页附件查看");
		customerFocusBehaviorMap.put("110205","超级理财师{0}产品详情页附件查看");
		customerFocusBehaviorMap.put("110206","超级理财师私募产品详情页附件查看");
		customerFocusBehaviorMap.put("110207","超级理财师{0}产品详情页");
		customerFocusBehaviorMap.put("110208","超级理财师私募产品详情页");

		productTypeMap = new TreeMap<String, String>();
		productTypeMap.put("02","集合信托");
		productTypeMap.put("03","集合资管");
		productTypeMap.put("07","债券基金");
		productTypeMap.put("06","股权基金");
	}
	
	/**
	 * 返利是否百分比
	 * @return
	 */
	public static Boolean isRatio(String rebateType) {
		return CommonConstantUtil.REBATE_RATIO.equals(rebateType); 
	}
	
	//TODO 枚举 
	/**
	 * 获得投资行业
	 * @param investType
	 * @return
	 */
	public static String getInvestDesc(String investType){
		if("01".equals(investType)){
			return "房地产类";
		}else if("02".equals(investType)){
			return "金融市场";
		}else if("03".equals(investType)){
			return "基础设施";
		}else if("04".equals(investType)){
			return "其他";
		}else if("05".equals(investType)){
			return "城投债";
		}else if("06".equals(investType)){
			return "工商企业";
		}
		return "其它";
	}
	
	public static String getProductTypeDesc(String ptype){
		if("01".equals(ptype)){
			return "基金";
		}else if("02".equals(ptype)){
			return "信托";
		}
		return "其它";
	}
	
	/**
	 * 销售状态
	 * @param status
	 * @return
	 */
	public static String getProductSaleStatusDesc(String status){
		if("01".equals(status)){
			return "未开始";
		}else if("02".equals(status)){
			return "预售中";
		}else if("03".equals(status)){
			return "募集中";
		}else if("04".equals(status)){
			return "已募满";
		}
		return "其它";
	}
	
	/**
	 * 付息方式
	 * @param status
	 * @return
	 */
	public static String getPaymentInterestTypeDesc(String status){
		if("01".equals(status)){
			return "按月付息";
		}else if("02".equals(status)){
			return "按季付息";
		}else if("03".equals(status)){
			return "按半年付息";
		}else if("04".equals(status)){
			return "按年付息";
		}else if("05".equals(status)){
			return "到期还本付息";
		}
		return "其它";
	}

	/**
	 * 预期收益计算，根据传入code返回预期收益区间
	 * annualRevenueStart收益下限,annualRevenueEnd收益上限
	 * @param annualRevenueCode
	 * @return map,预期收益的上下区间
	 */
	public static Map<String,Object> annualRevenueUtils(String annualRevenueCode){

		if(StringUtils.isBlank(annualRevenueCode)){
			annualRevenueCode = "";
		}

		StringBuffer strBuffer = new StringBuffer();

		String annualRevenueStartKey = "annualRevenueStart";
		String annualRevenueEndKey = "annualRevenueEnd";

		String annualRevenueKey = "annualRevenueKey";

		Map<String,Object> annualRevenueMap = new HashMap<String,Object>();

		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_EIGHT_WITHIN) >=0){
			//7%以内
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 0 and 6.99 ");
			}else{
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 0 and 6.99 ");
			}
		}
		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_EIGHT_TEN) >=0){
			//7-8%
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 7 and 7.99 ");
			}else{
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 7 and 7.99 ");
			}
		}
		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_TEN_FIRTH) >=0){
			//8-9%

			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 8 and 8.99 ");
			}else{
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 8 and 8.99 ");
			}
		}
		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_FIRTH_MORE) >=0){
			//9-10%
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 9 and 9.99 ");
			}else{
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT between 9 and 9.99 ");
			}
		}

		if(annualRevenueCode.indexOf("05") >=0){
			//10%以上
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT >= 10 ");
			}else{
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT >= 10 ");
			}
		}

		if(annualRevenueCode.indexOf("06") >=0){
			//不限  浮动
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT like '%浮动%' ");
			}else{
				strBuffer.append(" fpar.P_ANNUAL_REVENUE_EXPECT like '%浮动%' ");
			}
		}
		annualRevenueMap.put(annualRevenueKey, strBuffer.toString());
		return annualRevenueMap;

	}
	/**
	 * 产品期限计算，根据传入code返回期限天数
	 * dueTimeStart期限上限天数,dueTimeEnd期限下限天数
	 * @param dueTimeCode
	 * @return map,产品期限的上下区间
	 */
	public static Map<String,Object> dueTimeUtils(String dueTimeCode){

		if(StringUtils.isBlank(dueTimeCode)){
			dueTimeCode = "";
		}

		StringBuffer strBuffer = new StringBuffer();
		
		int yearDay = 12;
		int dueTimeStart = 0;
		int dueTimeEnd = 0;
		String dueTimeStartKey = "dueTimeStart";
		String dueTimeEndKey = "dueTimeEnd";
		
		String dueTimeKey = "dueTimeQuery";
		
		Map<String,Object> dueTimeMap = new HashMap<String,Object>();
		
		if(dueTimeCode.indexOf("01") >=0){
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME between 0 and 5 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME between 0 and 5 ");
			}
			//6个月内
			
		}
		if(dueTimeCode.indexOf("02") >=0){
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME between 6 and 11 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME between 6 and 11 ");
			}
			//6-11个月
		}
		
		if(dueTimeCode.indexOf("03") >=0){
			
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME = 12 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME = 12 ");
			}
			//12个月
		}
		
		if(dueTimeCode.indexOf("04") >=0){
			
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME between 13 and 23 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME between 13 and 23 ");
			}
			// 13-23个月
		}
		
		if(dueTimeCode.indexOf("05") >=0){
			
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME = 24 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME = 24 ");
			}
			// 13-23个月
		}

		if(dueTimeCode.indexOf("06") >=0){
			
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME >24 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME >24");
			}
			//2年以上(含3年)
		}if(dueTimeCode.indexOf("07") >=0){
			//不限
		}
		dueTimeMap.put(dueTimeKey, strBuffer.toString());
		return dueTimeMap;
		
	}

	public static String  pShortNameUtils(String string) {
		
		StringBuffer sb = new StringBuffer();
		
		if(StringUtils.isBlank(string)){
			return "";
		}
		char[] a = string.toCharArray();
		for (int i = 0; i < a.length; i++) {
			char c = a[i];
			
			if(sb.length() > 0){
				sb.append(" and ");
				sb.append(" p.P_NAME like CONCAT('%',");
				sb.append("'"+c+"'");
				sb.append(",'%') ");
				
			}else{
				sb.append(" p.P_NAME like CONCAT('%',");
				sb.append("'"+c+"'");
				sb.append(",'%') ");
			}
			
		}
		
		return sb.toString();
		
	}
	public static void main(String[] args) {
		
		System.out.println(pShortNameUtils("你好"));
	}
	
}